home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C++ / Code Resources / NeXT CDEF / NeXT CDEF Tester ƒ / NeXT CDEF Tester.c++ next >
Encoding:
C/C++ Source or Header  |  1994-05-04  |  5.8 KB  |  229 lines  |  [TEXT/KAHL]

  1. /*
  2.  
  3.         NeXT CDEF Tester.c++
  4.         Version 1.0
  5.         
  6.         by Hiep Dam, 3G Software
  7.         This file & code in this file public domain.
  8.         Contacting author:
  9.             America Online: StarLabs
  10.             Delphi          : StarLabs
  11.             Internet      : starlabs@aol.com, starlabs@delphi.com
  12.  
  13.         Last update: May 4, 1994
  14.  
  15. */
  16.  
  17.  
  18. enum {
  19.     exitBtn = 1,
  20.     stdCheckBtn = 2,
  21.     stdRadioBtn = 3,
  22.     NeXTBtn1 = 4,
  23.     disabledNeXTBtn = 5,
  24.     sysFontNeXTBtn = 6,
  25.     geneva9NeXTBtn = 7,
  26.     cicnBtn1 = 8,
  27.     cicnBtn2 = 9,
  28.     smallCicnBtn = 10,
  29.     flipCicnBtn1 = 11,
  30.     flipCicnBtn2 = 12,
  31.     NeXTBtn1Status = 13,
  32.     disabledNeXTBtnStatus = 14,
  33.     sysFontNeXTBtnStatus = 15,
  34.     geneva9NeXTBtnStatus = 16,
  35.     cicnBtn1Status = 17,
  36.     cicnBtn2Status = 18,
  37.     smallCicnBtnStatus = 19,
  38.     checkBox1 = 23,
  39.     checkBox2 = 24,
  40.     checkBox3 = 25,
  41.     radio1 = 26,
  42.     radio2 = 27,
  43.     radio3 = 28,
  44.     checkBoxBegin = checkBox1,
  45.     checkBoxEnd = radio3,
  46.     checkBoxDisable = 29,
  47.  
  48.     statusOffset = 9,            // NeXTBtn1Status - NeXTBtn1
  49.     
  50.     windowFont = systemFont,
  51.     windowFontSize = 12
  52. };
  53.  
  54. void InitMac();
  55. void DoDialog();
  56. void DrawControlValue(short theVal);
  57. void HandleMovableDialog(EventRecord *theEvent);
  58.  
  59. DialogPtr theDialog;
  60.  
  61.  
  62. void main() {
  63.     InitMac();
  64.     DoDialog();
  65. } // END main
  66.  
  67. void DoDialog() {    
  68.     Handle itemH; short itemT; Rect itemR;
  69.  
  70.     theDialog = GetNewDialog(128, nil, (WindowPtr)-1);
  71.     SetPort(theDialog);
  72.     TextFont(windowFont);
  73.     TextSize(windowFontSize);
  74.  
  75.     ShowWindow(theDialog);
  76.  
  77.     short itemHit, controlValue, onValue, offValue;
  78.     do {
  79.         EventRecord theEvent; Boolean eventExists;
  80.         eventExists = GetNextEvent(everyEvent, &theEvent);
  81.         HandleMovableDialog(&theEvent);
  82.         if (IsDialogEvent(&theEvent)) {
  83.             if (DialogSelect(&theEvent, &theDialog, &itemHit)) {
  84.                 switch(itemHit) {
  85.                     case stdCheckBtn:
  86.                     case stdRadioBtn:
  87.                         GetDItem(theDialog, itemHit, &itemT, &itemH, &itemR);
  88.                         controlValue = GetCtlValue((ControlHandle)itemH);
  89.                         controlValue = !controlValue;
  90.                         SetCtlValue((ControlHandle)itemH, controlValue);
  91.                         DrawControlValue(controlValue);
  92.                     break;
  93.         
  94.                     case flipCicnBtn1:
  95.                     case flipCicnBtn2: {
  96.                         GetDItem(theDialog, itemHit, &itemT, &itemH, &itemR);
  97.                         controlValue = GetCtlValue((ControlHandle)itemH);
  98.                         onValue = GetCtlMax((ControlHandle)itemH);
  99.                         offValue = GetCtlMin((ControlHandle)itemH);
  100.                         if (controlValue == onValue)
  101.                             controlValue = offValue;
  102.                         else
  103.                             controlValue = onValue;
  104.                         SetCtlValue((ControlHandle)itemH, controlValue);
  105.                         DrawControlValue(controlValue);
  106.                     } break;
  107.         
  108.                     case NeXTBtn1Status:
  109.                     case disabledNeXTBtnStatus:
  110.                     case sysFontNeXTBtnStatus:
  111.                     case geneva9NeXTBtnStatus:
  112.                     case cicnBtn1Status:
  113.                     case cicnBtn2Status:
  114.                     case smallCicnBtnStatus:
  115.                     case checkBoxDisable:
  116.                         GetDItem(theDialog, itemHit, &itemT, &itemH, &itemR);
  117.                         controlValue = GetCtlValue((ControlHandle)itemH);
  118.                         onValue = GetCtlMax((ControlHandle)itemH);
  119.                         offValue = GetCtlMin((ControlHandle)itemH);
  120.                         if (controlValue == onValue)
  121.                             controlValue = offValue;
  122.                         else
  123.                             controlValue = onValue;
  124.                         SetCtlValue((ControlHandle)itemH, controlValue);
  125.                         if (itemHit == checkBoxDisable) {
  126.                             for (short i = checkBoxBegin; i <= checkBoxEnd; i++) {
  127.                                 GetDItem(theDialog, i, &itemT, &itemH, &itemR);
  128.                                 if (itemT < 4 || itemT > 7)
  129.                                     continue;
  130.                                 if (controlValue == onValue)
  131.                                     HiliteControl((ControlHandle)itemH, 0);
  132.                                 else
  133.                                     HiliteControl((ControlHandle)itemH, 255);
  134.                             }
  135.                         }
  136.                         else {
  137.                             GetDItem(theDialog, itemHit - statusOffset, &itemT, &itemH, &itemR);
  138.                             if (controlValue == onValue)
  139.                                 HiliteControl((ControlHandle)itemH, 0);
  140.                             else
  141.                                 HiliteControl((ControlHandle)itemH, 255);
  142.                         }
  143.                         DrawControlValue(controlValue);
  144.                     break;
  145.  
  146.                     case radio1:
  147.                     case radio2:
  148.                     case radio3:
  149.                         for (short i = radio1; i <= radio3; i++) {
  150.                             GetDItem(theDialog, i, &itemT, &itemH, &itemR);
  151.                             SetCtlValue((ControlHandle)itemH, 0);
  152.                         }
  153.                         GetDItem(theDialog, itemHit, &itemT, &itemH, &itemR);
  154.                         SetCtlValue((ControlHandle)itemH, 1);
  155.                     break;
  156.  
  157.                     case checkBox1:
  158.                     case checkBox2:
  159.                     case checkBox3:
  160.                         GetDItem(theDialog, itemHit, &itemT, &itemH, &itemR);
  161.                         controlValue = GetCtlValue((ControlHandle)itemH);
  162.                         controlValue = !controlValue;
  163.                         SetCtlValue((ControlHandle)itemH, controlValue);
  164.                         DrawControlValue(controlValue);
  165.                     break;
  166.                 } // END switch
  167.             }
  168.         }
  169.     } while (itemHit != exitBtn);
  170. } // END DoDialog
  171.  
  172. void HandleMovableDialog(EventRecord *theEvent) {
  173.     if (theEvent->what == mouseDown) {
  174.         short mouseLoc;
  175.         WindowPtr theWindow;
  176.  
  177.         mouseLoc = FindWindow(theEvent->where, &theWindow);
  178.         switch (mouseLoc) {
  179.             case inDrag: {
  180.                 Rect dragRect = screenBits.bounds;
  181.                 InsetRect(&dragRect, 10, 10);
  182.                 DragWindow(theWindow, theEvent->where, &dragRect);
  183.             } break;
  184.             
  185.             default: {
  186.             } break;
  187.         } // END switch
  188.     }
  189.     else if (theEvent->what == keyDown) {
  190.         short itemT; Handle itemH; Rect itemR;
  191.         GetDItem(theDialog, 1, &itemT, &itemH, &itemR);
  192.         HiliteControl((ControlHandle)itemH, inButton);
  193.         long dummy;
  194.         Delay(7, &dummy);
  195.         HiliteControl((ControlHandle)itemH, 0);
  196.         ExitToShell();
  197.     }
  198. } // END HandleMovableDialog
  199.  
  200. void DrawControlValue(short theVal) {
  201.     RGBColor RGBltGray, RGBwhite;
  202.     RGBltGray.red = RGBltGray.blue = RGBltGray.green = 56797;
  203.     RGBwhite.red = RGBwhite.blue = RGBwhite.green = 65535;
  204.     TextFont(geneva);
  205.     TextSize(9);
  206.     TextMode(srcCopy);
  207.     RGBBackColor(&RGBltGray);
  208.  
  209.     Str255 tempStr;
  210.     NumToString(theVal, tempStr);
  211.     MoveTo(theDialog->portRect.left + 10, theDialog->portRect.bottom - 6);
  212.     DrawString("\pValue: "); DrawString(tempStr); DrawString("\p       ");
  213.  
  214.     TextFont(windowFont);
  215.     TextSize(windowFontSize);
  216.     TextMode(srcOr);
  217.     RGBBackColor(&RGBwhite);
  218. } // END DrawControlValue
  219.  
  220. void InitMac() {
  221.     InitGraf(&thePort);
  222.     InitFonts();
  223.     FlushEvents(everyEvent,0);
  224.     InitWindows();
  225.     InitMenus();
  226.     TEInit();
  227.     InitDialogs(0L);
  228.     InitCursor();
  229. }